class IDestroyable:
    """ Interface for the objects that can suffer damage"""
    def __init__(self):
        self.__HPMax=100
        self.HP=100
        
        
    def setHPMax(self, iHPMax):
        """ Maximum number of hitpoints that this object can have"""
        self.__HPMax=iHPMax

    def RemainingHP(self):
        return self.__HP

    def DamageLevel(self):
        """ Percentage of hitpoints left"""
        return self.__HP/self.__HPMax
    

    def Inflict(self, iDamage):
        self.__HP = self.__-iDamage
        

    def Repair(self, iAmount):
        self.__HP = self.__HP+iAmount
        if self.__HP >= self.__HPMax :
            self.__HP = self.__HPMax
            return True
        return False

class ITimerUpdatable:
    
    def timerUpdate(self, iTimeInterval):
        """ The usual function a supervisor calls at given time intervals.
        Usually used to update position and animate objects...
        If returns False, the main loop stops."""
        return True
  
class ISelectable:
    def getSelected(self)  :
        return self.__selected
    
    def setSelected(self, value):
        self.__selected=value
        
    Selected=property(getSelected,setSelected)

def intersect(A,B,C,D):
    Ax,Ay=A
    Bx,By=B
    Cx,Cy=C
    Dx,Dy=D

    num=(Ay-Cy)*(Dx-Cx)-(Ax-Cx)*(Dy-Cy)
    den=(Bx-Ax)*(Dy-Cy)-(By-Ay)*(Dx-Cx)
		
    if (den==0):
        print "Parallel !"
        return False
    if num*den<0 :
                return False
    
    from math import fabs
    if math.fabs(num)>math.fabs(den): return False
    
    return True

def isHiddenBy(A,B,obstacle):
    SegA=obstacle[0]
    
    for i in range(1,len(obstacle)):
        SegB=obstacle[i]
        if intersect(A,B,SegA,SegB):
            return True
        SegA=SegB
    return False
        
if __name__ == '__main__':
    A=(0,0)
    B=(1,1)
    C=(-1,0)
    D=(0,-1)
    print intersect(A,B,C,D)